package org.tc.product.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.tc.product.entity.Commoditys;
import org.tc.product.entity.Secondcommoditys;
import org.tc.product.mapper.CommoditysMapper;
import org.tc.product.mapper.SecondcommoditysMapper;
import org.tc.product.service.SecondcommoditysService;

import java.util.List;

@Service
@RestController
public class SecondcommoditysServiceImpl implements SecondcommoditysService {

    @Autowired
    private SecondcommoditysMapper secondcommoditysMapper;

    @Autowired
    private CommoditysMapper commoditysMapper;

    @Override
    public int deleteSecById(Integer id, Integer commodityid, Integer stock, Integer storeid) {
        int count = 0;
        count = secondcommoditysMapper.deleteByPrimaryKey(id);
        Commoditys commoditys = commoditysMapper.selectComById(commodityid);
        stock += commoditys.getStock();
        commoditys = new Commoditys();
        commoditys.setId(commodityid);
        commoditys.setStock(stock);
        count = commoditysMapper.updcom(commoditys);
        return count;
    }

    @Override
    public int insertSec(@RequestBody Secondcommoditys secondcommoditys) {
        int count = secondcommoditysMapper.insert(secondcommoditys);
        return count;
    }

//    @Override
//    public PageHelper<Secondcommoditys> selectAllSec(int pageNo, int pageSize, Integer storeid, Integer state) {
//        PageHelper<Secondcommoditys> pageHelper = new PageHelper<>();
//        pageHelper.setPageNo(pageNo);
//        pageHelper.setPageSize(pageSize);
//        List<Secondcommoditys> slist = secondcommoditysMapper.selectAllSec(pageHelper.getFirstResult(), pageHelper.getPageSize(), storeid);
//        pageHelper.setData(slist);
//        int sumCount = secondcommoditysMapper.getSecCount(storeid);
//        int pageCount = sumCount % pageSize == 0 ? sumCount / pageSize : sumCount / pageSize + 1;
//        pageHelper.setPageCount(sumCount);
//        return pageHelper;
//    }

    @Override
    public int updSec(@RequestBody Secondcommoditys secondcommoditys) {
        return secondcommoditysMapper.updateByPrimaryKey(secondcommoditys);
    }

    @Override
    public List<Secondcommoditys> QueryAllSecond(Integer storeid) {
        return secondcommoditysMapper.QueryAllSecond(storeid);
    }

    @Override
    public List<Secondcommoditys> selectAll(Integer storeid, Integer state) {
        return secondcommoditysMapper.selectAll(storeid, state);
    }
}
